<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;

class CoachOrder extends Model
{
    protected $fillable = [
        'tenant_id',
        'user_id',
        'coach_id',
        'order_sn',
        'sale_num',
        'transaction_id',
        'openid',
        'body',
        'total_fee',
        'is_paid',
        'paid_time',
    ];

    public function tenant()
    {
        return $this->belongsTo(Tenant::class);
    }

    public function coach()
    {
        return $this->belongsTo(Coach::class);
    }

    public function user()
    {
        return $this->belongsTo(User::class);
    }

    /**
     * 生成订单号
     * @return string
     */
    public static function generateOrderNo($prefix = '')
    {
        return $prefix . date('YmdHis') . str_pad(mt_rand(1, 99999), 5, '0', STR_PAD_LEFT);
    }
}
